<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Index_Admin extends CI_Controller {

	public function __construct(){
		parent::__construct();
		header('Content-type:application/x-www-form-urlencoded');
	}

	public function index()
	{	
		/**
     * 模拟post进行url请求
     * @param string $url
     * @param string $param
     */
    
        // if (empty($url) || empty($param)) {
        //     return false;
        // }    

        
		
        //$hash_hmac = hash_hmac("sha512",json,$key);
       // echo _echo(hash_hmac('sha512', _echo($post_data), '7bd5de940d924ce7a038d5ae0046dd09383fb04d4b6848cc834adbac0ce15f5a')); die;
       		
       // $res = $this->request_post($url, _echo($post_data));

        //$data['error'] = error('4008');	
        
		//echo _echo($res); 
       
		//$this->load->view('admin/index');
	}

	/**
     * 模拟post进行url请求
     * @param string $url
     * @param array $post_data
     */
    function request_post() {
        

        $url = 'http://180.169.48.172:38790/mapi_v1/get_package';
        $post_data['id']         = 'd0aaf17a-6782-4edb-9ea5-b274d611e1aa';
        $post_data['ts']         = time();
        $post_data['device_id']  = '866666030863998';
        $post_data['package_id'] = '';

        $sign = hash_hmac('sha512', json_encode($post_data), '7bd5de940d924ce7a038d5ae0046dd09383fb04d4b6848cc834adbac0ce15f5a');
        
        $header['sign'] = $sign;
        $header['uid'] = 'd0aaf17a-6782-4edb-9ea5-b274d611e1aa';
        
        $postUrl = $url;
        $curlPost = $post_data;
        
        $ch = curl_init();//初始化curl
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);//要求结果为字符串且输出到屏幕上
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type:application/x-www-form-urlencoded','sign:'.strlen($sign),'uid:d0aaf17a-6782-4edb-9ea5-b274d611e1aa')); 
        //curl_setopt($ch, CURLOPT_HEADER, false);
        //curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
        curl_setopt($ch, CURLOPT_URL,$postUrl);//抓取指定网页
        curl_setopt($ch, CURLOPT_POST, true);//post提交方式
        curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
        $data = curl_exec($ch);//运行curl
        

        curl_close($ch);
            
        return $data;
    }
}

